// pages/course-info/course-info.js
import request from '../../utils/request'

Page({
  data: {
    banners:[],
    userList:[],
    courseName: '',
    // courseTime: '',
    coachName: '',
    storeName: '',
    address: '',
    city:'',
    content: `<div style="display: flex; flex-direction: column;align-items: center;">
   <img src='/images/yujia.png' 
   style="width: 300px; height: 185px; margin-bottom: 10px;">
   
   <img src='/images/yujia.png' 
   style="width: 300PX; height: 185px; margin-bottom: 5px;">
   
   <p style="width: 317px; font-size: 16px; color: #919191; margin: 10px 0;">
   “当你倾听自己时，一切都自然而然。它来自内心，就像一种做某事的意愿。试着敏感一点。那是瑜伽。"</p>
   
   <img src='/images/yujia.png' style="width: 300PX; height: 185px; margin-bottom: 10px;">
  </div>`,
    detail:'',
    id:null
  },

  onLoad(options) {
    // console.log(options);
    this.getInfo(options.id);
    this.setData({
      id:options.id
    })
  },
  getInfo(id) {
    console.log(id);
    request({
      url: '/course/info/' + id,
      method: 'GET',
    }).then(res => {
      console.log(res);
      if (res.code === 200) {
        let data = res.data
        this.setData({
          banners: data.bannerList,
          courseName: data.courseName,
          courseTime: data.startTime + data.endTime,
          coachName: data.coachName,
          storeName: data.storeName,
          address: data.city + data.address,
          detail:data.detail
        })
      } else {
        wx.showToast({
          icon: 'error',
          title: res.message,
        })
      }
    }).catch(err => {
      console.error(err);
    });
  },
  // },
  // scrollToTop() {
  //   this.setAction({
  //     scrollTop: 0
  //   })
  // },

  map(e) {
    console.log(e)
    wx.openLocation({
      latitude: 22.669920,
      longitude: 113.827609,
      // scale: 18,
      address: "",
      name: "",
      success: (res) => {
        console.log('成功获取')
      },
      fail: (res) => {
        console.log("shibai")
      }
    })
    // console.log(res)
  },
  jumpToDetail(){
    var that =this
    wx.showModal({
      title: '确定预约课程？？？？？？',
      // content: '这是一个模态弹窗',
      success (res) {
        if (res.confirm) {
          console.log('用户点击确定')
          wx.navigateTo({
            url: '../course-appoint/course-appoint?id='+ that.data.id,
          })
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  }
  
})